package com.learn.controller;

import com.learn.entity.User;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 《Spring源码尝试解析》第11章 SpringMVC P293
 * 控制器用于处理 Web 请求，每个控制器都对应着一个逻辑处理
 */
// AbstractController extends WebContentGenerator implements Controller {
public class UserController extends AbstractController { // public class UserController implements Controller{

	// http://localhost:8080/learn_mvc/userList.htm
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest,
												 HttpServletResponse httpServletResponse) throws Exception {
		List<User> userList = new ArrayList<User>();
		User userA = new User();
		User userB = new User();
		userA.setUsername("张三");
		userA.setAge(27);
		userB.setUsername("李四");
		userB.setAge(37);
		userList.add(userA);
		userList.add(userB);
		return new ModelAndView("userlist", "users", userList);
	} /* 浏览器输出：
		This is SpringMVC demo page
		张三
		27
		李四
		37
	*///~
}